package cn.lopr.hfbdqn.service;

import cn.lopr.hfbdqn.common.Result;
import cn.lopr.hfbdqn.dao.ImgMapper;
import cn.lopr.hfbdqn.pojo.Img;
import cn.lopr.hfbdqn.route.ImgRoute;
import cn.lopr.mvc.frame.annotaion.Autowired;
import cn.lopr.mvc.frame.annotaion.Service;

import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Stream;

/**
 * @author shuangyang7
 * @date 2021/7/19 22:01
 */
@Service
public class ImgService implements ImgRoute {
    @Autowired
    ImgMapper imgMapper;

    @Override
    public Result<?> getImg() {
        List<Img> imgs = imgMapper.selectByEnableAndNotDelete();

        Stream<Img> imgBanner = imgs.stream().filter(img -> img.getImgType() == Img.ImgTypeE.BANNER.code).sorted(Comparator.comparing(Img::getImgSort));
        Stream<Img> imgKingKongDistrict = imgs.stream().filter(img -> img.getImgType() == Img.ImgTypeE.KING_KONG_DISTRICT.code).sorted(Comparator.comparing(Img::getImgSort));
        Stream<Img> imgFooter = imgs.stream().filter(img -> img.getImgType() == Img.ImgTypeE.FOOTER.code).sorted(Comparator.comparing(Img::getImgSort));

        return new Result<>(Result.SUCCESS, new HashMap<String, Object>() {{
            put("0", imgBanner.toArray());
            put("1", imgKingKongDistrict.toArray());
            put("2", imgFooter.toArray());
        }});
    }
}
